Skip to content

Studio tests: one Rust fake program from test-support, and the Windows research note (#813) - #816

Merged
danielrispler merged 2 commits into
mainfrom
issue-813-studio-tests-fake-programs
Nov 28, 2026
Merged

danielrispler merged 2 commits into
mainfrom
issue-813-studio-tests-fake-programs

Conversation

@danielrispler

Copy link
Copy Markdown
Owner

Closes #813 (spec #805).

Summary

A test fakes a program with one Rust call, not a #!/bin/sh script. The fake is the test's own binary, hard-linked (or copied, across filesystems) under the program's name, with a behaviour file beside it; a ctor hook acts it out before the test harness's main.

fake(dir, "git", Behaviour { stdout, stderr, code, wait, record })  -> dir/git (git.exe on Windows)
  place()          hard link to current_exe(); AlreadyExists = done; CrossesDevices -> copy to temp, rename
  write_whole()    dir/git.fake.json via temp + rename (a running call never reads half of it)

dir/git ... (started by the code under test)
  ctor: dir/git.fake.json beside current_exe()?  no -> run the test harness as usual
    record?  lock dir/git.record.lock, append {args, cwd, stdin, env} to dir/git.record.json
    print stdout, stderr; sleep wait; exit code

calls(dir/git) -> Vec<Call>, oldest first; a rewrite keeps the record
 test-support/
 ├── Cargo.toml          # + ctor (test-support is only ever a dev-dependency)
 ├── src/lib.rs          # + pub mod fake
+├── src/fake.rs
+└── tests/fake.rs
 workbench/tests/run.rs  # its `fake` git/gh is the Rust fake; tests read the record, not printed lines
 AGENTS.md               # Tests: new fakes are Rust; no new bare `sh`/`bash`
+docs/studio/research/windows.md   # the research note and CI spike results, the spec's first PR

The other 37 shell fakes stay until the Windows port (#805, Q5). system-map.json is unchanged: test-support/ and docs/ are already in ignored.

Evidence

test-support/tests/fake.rs, each run red (an assertion failure) before its fix:

a_fake_prints_what_it_was_told_and_exits_with_its_code
a_fake_records_arguments_folder_stdin_and_environment_one_entry_per_call
a_fake_waits_when_told
a_rewrite_changes_what_the_next_call_does          call, rewrite, call -> 2 entries, each its own behaviour
concurrent_calls_each_leave_one_whole_entry        40 parallel calls -> 40 entries (was 26)
a_fake_made_twice_at_once_and_rewritten_while_running_still_runs
                                                   before: the racing copy truncated the test binary to 0 bytes
  • Before: workbench/tests/run.rs read the fake's printed args:/env:/stdin: lines from a #!/bin/sh script.
    After: the same three tests check the same facts (arguments, GIT_TERMINAL_PROMPT/GH_PROMPT_DISABLED, stdin, folder) from calls().
  • npm run check passes locally (macOS). The ubuntu job below is the Linux check of current_exe through a hard link; the copy fallback has no test, since neither macOS nor the runner gives a temp folder on another filesystem by default.

Tests removed or merged: none.

Correctness pass

A reviewer traced the fake under nextest and plain cargo test, on macOS and Linux (docker), and reproduced each finding before the fix commit (aefc73902):

  • Fixed: a racing fake() copied onto a hard link of its own source and truncated the running test binary; the copy fallback gave "Text file busy" (os error 26) on ~20% of spawns on Linux with a tmpfs temp folder; a rewrite mid-call let a call read half a behaviour file and abort; 40 concurrent recording calls left 26 entries; a rewrite cleared the record (story 24 wants both calls).
  • Rejected: recording the whole environment (the spec asks for it; the file lives in the test's temp folder); a recording fake blocking on an inherited stdin (the old read script did too; the runner passes Stdio::null()); a fake left from an older build never relinked (every caller uses a fresh temp folder).
  • Standards and spec axes: the AGENTS.md rule first read "no code or test starts sh or bash", false the day it landed (41 starts); it now binds new code and tests (story 28). Stale run.rs doc and dead let _ = out; fixed.

Outside review

skipped: no risk match

Merge Danger

Door: two-way

Test-only code and docs; nothing shipped links test-support.

Blast Radius: tests

The ctor hook runs at the start of every test binary that links test-support and returns at once unless a .fake.json sits beside it (50 harness starts: 0.23 s in all).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CVqACdL6QruKkvHdjdYPVr

danielrispler and others added 2 commits November 28, 2026 17:42
…s research note (#813)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVqACdL6QruKkvHdjdYPVr
…llback, and keeps its record (#813)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CVqACdL6QruKkvHdjdYPVr
@danielrispler
danielrispler merged commit 951f827 into main Nov 28, 2026
11 checks passed
@danielrispler
danielrispler deleted the issue-813-studio-tests-fake-programs branch November 28, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio: tests fake programs with one Rust fake from test-support (#805)

1 participant